import { getCode } from '@/api/login.js'
import { ValidationProvider, ValidationObserver } from 'vee-validate'
import { v4 as uuidv4 } from 'uuid'

export default {
  data () {
    return {
      svg: '',
      code: ''
    }
  },
  components: {
    ValidationProvider,
    ValidationObserver
  },
  mounted () {
    let sid = ''
    if (localStorage.getItem('sid')) {
      sid = localStorage.getItem('sid')
    } else {
      sid = uuidv4()
      localStorage.setItem('sid', sid)
    }
    this.$store.commit('setSid', sid)
    this.getCaptcha()
  },
  methods: {
    async getCaptcha () {
      const sid = this.$store.state.sid
      const res = await getCode(sid)

      if (res.code === 200) {
        this.svg = res.data
      }
    }
  }
}
